package com.foo.aop.Aspect;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class AOPExceptionHandling 
{
	private final Log logger = LogFactory.getLog(this.getClass());
	
	/*
	 * Join Points are Data Access Classes and Service Classes
	 */
	@AfterThrowing(pointcut = "com.foo.aop.Aspect.SystemArchitecture.businessService()", throwing = "exception" )
	public void logError(JoinPoint joinPoint,Throwable exception)
	{
		StringBuilder logMessage = new StringBuilder();
		logMessage.append("Class Name: " + joinPoint.getTarget().getClass().getName());
		logMessage.append("Method Name: " + joinPoint.getSignature().getName());
		logMessage.append("Exception Message: " + exception.getMessage());
		//TODO: Could handle connection close
		logger.info("Exception Handled in AOPExceptionHandler: Details are: \n" + logMessage.toString(),exception);
	}
	
	//@After()
	public void releaseResources()
	{
		
	}
}
